package com.hospital.modules.sys.controller;

import com.hospital.common.utils.PageUtils;
import com.hospital.common.utils.R;
import com.hospital.modules.sys.entity.SysRecommenderEntity;
import com.hospital.modules.sys.entity.dto.RecommenderSearchByKeyDTO;
import com.hospital.modules.sys.service.SysRecommenderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 推荐人
 *
 * @author geaofeng
 * @email geaofeng@gmail.com
 * @date 2020-12-14 23:18:36
 */
@RestController
@RequestMapping("sys/sysrecommender")
public class SysRecommenderController extends AbstractController{
    @Autowired
    private SysRecommenderService sysRecommenderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysrecommender:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysRecommenderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sysrecommender:info")
    public R info(@PathVariable("id") Integer id){
		SysRecommenderEntity sysRecommender = sysRecommenderService.getById(id);

        return R.ok().put("sysRecommender", sysRecommender);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysrecommender:save")
    public R save(@RequestBody SysRecommenderEntity sysRecommender){
		sysRecommenderService.insert(sysRecommender, getUserId().intValue());

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysrecommender:update")
    public R update(@RequestBody SysRecommenderEntity sysRecommender){
		sysRecommenderService.modify(sysRecommender, getUserId().intValue());

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysrecommender:delete")
    public R delete(@RequestBody Integer[] ids){
		sysRecommenderService.delete(Arrays.asList(ids), getUserId().intValue());

        return R.ok();
    }

    @GetMapping("/search")
    public R search() {
        List<RecommenderSearchByKeyDTO> result = sysRecommenderService.search();
        return R.ok().put("data", result);
    }

}
